package com.social.controller;

import com.alibaba.fastjson.JSON;
import com.social.pojo.AuditNcmForm;
import com.social.pojo.NotificationCaseManagement;
import com.social.service.AuditNcmFormService;
import com.social.service.NotificationCaseManagementService;
import com.social.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 已发送补缴通知案件管理
 */
@Controller
@RequestMapping("NotificationCaseManagement")
public class NotificationCaseManagementController {
    /**
     * NotificationCaseManagement 业务层对象
     */
    @Autowired
    private NotificationCaseManagementService notificationCaseManagement;
    /**
     * AuditNcmForm 业务层对象
     */
    @Autowired
    private AuditNcmFormService auditNcmForm;

    /**
     * @param notificationCaseManagement 实体类对象
     * @param s                          状态
     * @return 修改状态
     */
    @RequestMapping("update")
    @ResponseBody
    public String update(NotificationCaseManagement notificationCaseManagement, Integer s) {
        //修改状态
        int status = 0;
        //查询方法
        NotificationCaseManagement notificationCaseManagements = this.notificationCaseManagement.selectByRegistrationOfCasesId(notificationCaseManagement.getRegistrationOfCasesId());
        //判断查询数据为空时添加
        if (notificationCaseManagements == null) {
            status = this.notificationCaseManagement.insertSelective(notificationCaseManagement);
        } else {
            status = this.notificationCaseManagement.updateByRegistrationOfCasesId(notificationCaseManagement);
        }
        if (s != null) {
            //查询缴费基数
            AuditNcmForm auditNcmForm = this.auditNcmForm.selectByRegistrationOfCasesId(notificationCaseManagement.getRegistrationOfCasesId());
            if (auditNcmForm != null) {
                //修改缴费基数
                status = this.auditNcmForm.updateByRegistrationOfCasesIdSelective(notificationCaseManagement.getRegistrationOfCasesId(), null, auditNcmForm.getBaseOfPayment() + 25);
            }
        }
        //返回数据
        JsonUtil jsonUtil = new JsonUtil();
        //设置状态
        Boolean restates = jsonUtil.getRestates(status);
        return JSON.toJSONString(restates);
    }
}
